<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    // 在全局(script元素中)定义一个变量,那么这个变量是可以在定义之后的任何范围被访问到,那么称为"全局变量"
    // 在函数内部定义的变量,只有在函数内才能进行访问,那么称为"局部变量"
    var message = "Hello World"
    function sayHello() {
      var nickname = "coderwhy"
      console.log("sayHello中访问message:", message)
      console.log("sayHello中访问nickname:", nickname)
      function hi() {
        console.log("在hi中访问message:", message)
        console.log("在hi中访问nickname:", nickname)
      }
      hi()
    }
    sayHello()
  </script>
</body>

</html>